package com.hulk.dryad.manage.framework.websocket.server.config;

import com.hulk.dryad.manage.boot.launch.DryadLogLevel;
import lombok.Getter;
import lombok.Setter;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.lang.Nullable;
import java.util.ArrayList;
import java.util.List;

/**
 * websocket 服务端配置
 *
 * @author
 */
@Getter
@Setter
@ConfigurationProperties(prefix = WebSocketServerProperties.PREFIX)
public class WebSocketServerProperties {

	static final String PREFIX = "websocket.server";

	/**
	 * 是否启用websocket 服务端
	 */
	private boolean enabled = true;
	/**
	 * 端点
	 */
	private List<String> endpoints = new ArrayList<>();
	/**
	 * 跨域设置
	 */
	private List<String> allowedOriginPatterns = new ArrayList<String>() ;
	/**
	 * 对外端点
	 * 订阅Broker名称 user点对点 topic广播即群发
	 */
	private List<String> simpleBrokers = new ArrayList<>();
	/**
	 * 全局使用的消息前缀
	 * 指服务端接收地址的前缀，意思就是说客户端给服务端发消息的地址的前缀。
	 * setApplicationDestinationPrefixes("/app/") @MessageMapping("/hello/top")
	 * 客户端发送写  stompClient.send("/app/hello/top", {}, inp.val());
	 */
	@Nullable
	private String[] applicationDestinationPrefixes;
	/**
	 * 点对点端点前缀
	 * 指客户端订阅的前缀，无需配置 默认/user
	 * setUserDestinationPrefix("/user/"),这里客户端订阅的是/user/{token}/msg
	 */
	@Nullable
	private String userDestinationPrefix;


	/**
	 * 用户存储
	 */
	private UserStore userStore = new UserStore();

	/**
	 * 握手配置
	 */
	private Handshake handshake = new Handshake();

	@Getter
	@Setter
	public static class Handshake {
		/**
		 * 握手的日志级别，方便排查问题
		 */
		private DryadLogLevel logLevel = DryadLogLevel.HEADERS;
	}

	@Getter
	@Setter
	public static class UserStore {
		/**
		 * 启用在线用户存储，默认：false
		 */
		private Boolean enabled = Boolean.FALSE;
		/**
		 * 用户存储名称，默认：redis
		 */
		private String name ;
	}

}
